//
//  LoginViewController.m
//  TutorialsModule
//
//  Created by Diego on 13/10/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "LoginYoutubeViewController.h"


@implementation LoginYoutubeViewController
@synthesize txtUsrName;
@synthesize txtUsrPass;

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

	static NSString *CellIdentifier = @"loginCell";
	UILabel *mainLabel;
	UIImageView *photo;
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	if (cell == nil) {
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
		
	switch (indexPath.section) {
		case 0:
			switch (indexPath.row) {
				case 0:
					photo = [[[UIImageView alloc] initWithFrame:CGRectMake(90, 5, 100, 100)] autorelease];
					photo.autoresizingMask = UIViewAutoresizingNone;
					[cell.contentView addSubview:photo];
					cell.selectionStyle= UITableViewCellSelectionStyleNone;
					photo.image = [UIImage imageNamed:@"youtube_logo_large.png"];
					break;
				default:
					break;
			}
			break;
		case 1:
			switch (indexPath.row) {
				case 0:
					mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(5, 8, 80, 20)] autorelease];
					mainLabel.font = [UIFont systemFontOfSize:14.0];
					mainLabel.textAlignment = UITextAlignmentLeft;
					mainLabel.textColor = [UIColor blackColor];
					mainLabel.autoresizingMask = UIViewAutoresizingNone;
					[cell.contentView addSubview:mainLabel];
					mainLabel.text = @"User name:";
					
					mainLabel.highlighted = YES;
					txtUsrName = [[[UITextField alloc] initWithFrame:CGRectMake(90, 8, 100, 20)] autorelease];
					txtUsrName.text=@"ejemplossssss";
					txtUsrName.returnKeyType = UIReturnKeyDone;
					txtUsrName.delegate = self;
					[cell.contentView addSubview:txtUsrName];
					break;
				case 1:
					mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(5, 8, 80, 20)] autorelease];
					mainLabel.font = [UIFont systemFontOfSize:14.0];
					mainLabel.textAlignment = UITextAlignmentLeft;
					mainLabel.textColor = [UIColor blackColor];
					mainLabel.autoresizingMask = UIViewAutoresizingNone;
					[cell.contentView addSubview:mainLabel];
					mainLabel.text = @"Password:";
					mainLabel.highlighted=YES;
					txtUsrPass = [[[UITextField alloc] initWithFrame:CGRectMake(90, 8, 100, 20)] autorelease];
					txtUsrPass.text=@"ejemplossssss";
					txtUsrPass.returnKeyType = UIReturnKeyDone;
					txtUsrPass.delegate = self;
					//txtUsrPass.
					[cell.contentView addSubview:txtUsrPass];
					break;
			}
			break;
		case 2:
			cell.textLabel.text = @"Connect";
			break;
		}
	}
	return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
	return nil;//@"holaaaa";
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	[textField resignFirstResponder];
	return YES;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0)
		return 1;
	else if(section ==1)
		return 2;
	else if(section ==2)
		return 1;
	return 0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath {
	UITableViewCell *newCell = [tableView cellForRowAtIndexPath:newIndexPath];
	newCell.selected = NO;
	if (newIndexPath.section == 1) {
		
		/*for (int i=0; i<[newCell.subviews count]; i++) {
			NSObject * obj = [newCell.subviews objectAtIndex:i];
			NSLog(NSStringFromClass([obj class]));
		}*/
		
		NSObject * obj = [newCell.contentView.subviews objectAtIndex:1];
		if([obj isKindOfClass:[UITextField class]]){
			UITextField * txt = (UITextField *) obj;
			[txt becomeFirstResponder];
		}
	}
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath  
{  
	if (indexPath.section==0) {
		if (indexPath.row==0) {
			return 120;
		}
		else {
			return 40;
		}
	}
	else {
		return 40;
	}
} 

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	return YES;
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}

- (void)dealloc {
    [super dealloc];
}

-(IBAction) connectClick{}



@end
